import logging
import datetime

from django.http import HttpResponse
from django.http import HttpResponseRedirect

from django.core.urlresolvers import reverse
from google.appengine.ext import db
from django.shortcuts import render_to_response

from match.models import Match
from match.models import MatchPlayer


def match(request,match_id):
    match = Match.get_by_id(int(match_id))    
    return render_to_response('match/match.html',locals())
    
def end_match(request,match_id):
    match = Match.get_by_id(int(match_id))
    return render_to_response('match/end_match.html',locals())


def confirm(request,match_player):
    mp = MatchPlayer.get_by_id(int(match_player))
    mp.confirm = True
    mp.confirm_date = datetime.datetime.now()
    mp.put()
    return HttpResponseRedirect(reverse('match_match', kwargs={'match_id':mp.match.key().id()}))